import { defineStore } from "pinia";

// 状态管理 页面请求数据持久化
export const usePageStore = defineStore('pageRequest', {
  state: () => ({
    loginPopup: false, // 登录弹窗
    userInfo: {}, // 用户信息
  }),
  actions: {
    setLoginPopup(val) {
      this.loginPopup = !this.loginPopup;
    },
    resetUserInfo() {
      console.log('userInfo', this)
      this.userInfo = {};
    },
    // 用户登录
    userLogin({ loginPopup, userInfo }) {
      this.loginPopup = loginPopup;
      this.userInfo = userInfo;
    },
  },
  persist: {
    enabled: true, // true 表示开启持久化保存
    strategies: [{
      key: '_pageRequest',
      storage: localStorage
    }]
  }
})